﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;

namespace MvcApplication1.Controllers
{
    public class QuanLyHoTroKhachHangController : Controller
    {
        //
        // GET: /QuanLyHoTroKhachHang/

        public ActionResult QuanLyDichVuHoTro()
        {
            DataClassesDataContext dataContext = new DataClassesDataContext();
            var dsHoTro = from donDangKy in dataContext.DonDKDichVus select donDangKy;
            List<DonDangKyDichVuModel> dsDonDangKyModels = new List<DonDangKyDichVuModel>();
            foreach (DonDKDichVu donDangKy in dsHoTro)
            {
                DonDangKyDichVuModel donDangKyDichVuModel = new DonDangKyDichVuModel();
                string tenDangNhap = (from user in dataContext.KhachHangs where donDangKy.KhachHang_Id == user.Id select user).FirstOrDefault().UserName;
                donDangKyDichVuModel.tenDangNhap = tenDangNhap;
                string tenSanPham = (from sanPham in dataContext.SanPhams where sanPham.Id == donDangKy.SanPhamId select sanPham).FirstOrDefault().TenSp;
                donDangKyDichVuModel.tenSanPham = tenSanPham;
                donDangKyDichVuModel.ngayDangKy = donDangKy.NgayMuaSanPham;
                donDangKyDichVuModel.moTaChiTiet = donDangKy.MoTa;
                donDangKyDichVuModel.ngayDangKySuaChua = donDangKy.NgayDangKySuaChua;
                donDangKyDichVuModel.ngayGiaoHang = donDangKy.NgayGiaoHang;
                donDangKyDichVuModel.tinhTrang = donDangKy.TinhTrang;
                donDangKyDichVuModel.yKienPhanHoi = donDangKy.YKienPhanHoi;
                dsDonDangKyModels.Add(donDangKyDichVuModel);
            }
            ViewBag.dsDonDangKyModels = dsDonDangKyModels;
            ViewBag.MenuClass = Session["MenuClass"];
            return View();
        }

        [HttpPost]
        public JsonResult CapNhatDonHang(int donHangId)
        {
            DataClassesDataContext dataContext = new DataClassesDataContext();
            DonDKDichVu donDangKyDichVu = (from donDK in dataContext.DonDKDichVus where donDK.Id == donHangId select donDK).FirstOrDefault();
            donDangKyDichVu.TinhTrang = "Hoàn thành";
            donDangKyDichVu.NgayGiaoHang = DateTime.Now.ToShortDateString();
            dataContext.SubmitChanges();
            return this.Json(
                      new
                      {
                          Result = "success",
                          ngayCapNhat = donDangKyDichVu.NgayGiaoHang
                      }
                      , JsonRequestBehavior.AllowGet
                   );
        }

        public ActionResult QuanLyThacMacVaGiaiDap()
        {
            DataClassesDataContext dataContext = new DataClassesDataContext();
            var dsYKienPhanHoi = from ykien_phanhoi in dataContext.GopY_PhanHois select ykien_phanhoi;
            List<GopY_PhanhoiModel> dsGopY_PhanHoiModels = new List<GopY_PhanhoiModel>();
            foreach (GopY_PhanHoi gopy in dsYKienPhanHoi)
            {
                GopY_PhanhoiModel gopY_PhanHoiModel = new GopY_PhanhoiModel();
                string tenDangNhap = (from user in dataContext.KhachHangs where gopy.KhachHang_Id == user.Id select user).FirstOrDefault().UserName;
                gopY_PhanHoiModel.tenDangNhap = tenDangNhap;
                gopY_PhanHoiModel.noiDungGopY = gopy.NoiDung;
                gopY_PhanHoiModel.phanHoi = gopy.PhanHoi;
                dsGopY_PhanHoiModels.Add(gopY_PhanHoiModel);
            }
            ViewBag.dsDonDangKyModels = dsGopY_PhanHoiModels;
            ViewBag.MenuClass = Session["MenuClass"];
            return View();
        }

    }
}
